package ch12;

class ThreadEx08 implements Runnable {
	static boolean autoSave = false;

	public static void main(String[] args) {
		Thread t = new Thread(new ThreadEx08());
		t.setDaemon(true);
		t.start();

		for (int i = 1; i <= 20; i++) {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) { }			
			System.out.println(i);

			if (i == 5)	autoSave = true;
		}
		System.out.println("finish.");
	}

	public void run() {
		while (true) {
			try {
				Thread.sleep(3 * 1000); 
			} catch (InterruptedException e) { }

			if (autoSave) autoSave();
		}
	}

	private void autoSave() {
		System.out.println("save.");
	}
}
/*
1
2
3
4
5
6
save.
7
8
9
save.
10
11
save.
12
13
14
15
save.
16
17
18
save.
19
20
finish.
*/